/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * EventoAgregar.java
 *
 * Created on May 31, 2012, 1:56:47 AM
 */
package sistemadeproyectos;

import java.sql.*; // importamos java.sql para poder trabajar con SQL
import javax.swing.JOptionPane;

public class EventoAgregar extends javax.swing.JDialog {

 static String fecha;
 static String equipo;
    /** Creates new form EventoAgregar */
    public EventoAgregar(String fecha, String equipo) {
     
        this.fecha = fecha;
        this.equipo = equipo;        
        initComponents();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jScrollPane1 = new javax.swing.JScrollPane();
        jTextArea1 = new javax.swing.JTextArea();
        jButton2 = new javax.swing.JButton();
        jTextField1 = new javax.swing.JTextField();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jToggleButton1 = new javax.swing.JToggleButton();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        setName("Form"); // NOI18N

        jScrollPane1.setName("jScrollPane1"); // NOI18N

        jTextArea1.setColumns(20);
        jTextArea1.setRows(5);
        jTextArea1.setName("jTextArea1"); // NOI18N
        jScrollPane1.setViewportView(jTextArea1);

        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(sistemadeproyectos.SistemadeproyectosApp.class).getContext().getResourceMap(EventoAgregar.class);
        jButton2.setText(resourceMap.getString("jButton2.text")); // NOI18N
        jButton2.setName("jButton2"); // NOI18N
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });

        jTextField1.setText(resourceMap.getString("jTextField1.text")); // NOI18N
        jTextField1.setName("jTextField1"); // NOI18N

        jLabel1.setText(resourceMap.getString("jLabel1.text")); // NOI18N
        jLabel1.setName("jLabel1"); // NOI18N

        jLabel2.setText(resourceMap.getString("jLabel2.text")); // NOI18N
        jLabel2.setName("jLabel2"); // NOI18N

        jToggleButton1.setText(resourceMap.getString("jToggleButton1.text")); // NOI18N
        jToggleButton1.setName("jToggleButton1"); // NOI18N
        jToggleButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jToogleButtonOk(evt);
            }
        });

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(21, 21, 21)
                        .addComponent(jLabel1))
                    .addGroup(layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, 161, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(52, 52, 52)
                        .addComponent(jToggleButton1, javax.swing.GroupLayout.PREFERRED_SIZE, 64, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(46, 46, 46)
                        .addComponent(jButton2))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(124, 124, 124)
                        .addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 158, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(31, 31, 31)
                        .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 386, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(63, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                .addGap(18, 18, 18)
                .addComponent(jLabel2)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 194, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 24, Short.MAX_VALUE)
                .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 18, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, 41, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jButton2)
                    .addComponent(jToggleButton1))
                .addContainerGap())
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

/* Button2 es el boton de cancelar*/    
private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
  this.setVisible(false);
}//GEN-LAST:event_jButton2ActionPerformed

private void jToogleButtonOk(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jToogleButtonOk
  
  BDAdmin agreg = new BDAdmin("");
  
  String actividad;
  String hora;
  char dosPuntos1,dosPuntos2;
  char [] dst = new char[6];

  try{
  
  actividad = jTextArea1.getText();
  hora = jTextField1.getText();
  dst[0]=hora.charAt(0);
  dst[1]=hora.charAt(1);
  dst[2]=hora.charAt(3);
  dst[3]=hora.charAt(4);
  dst[4]=hora.charAt(6);
  dst[5]=hora.charAt(7);
  dosPuntos1 = hora.charAt(2);
  dosPuntos2 = hora.charAt(5);
  if(dosPuntos1 != ':' || dosPuntos2 != ':'){
        JOptionPane.showOptionDialog(
          this,
          "El formato de hora debe ser hh:mm:ss", //Mensaje
          "",
          JOptionPane.OK_OPTION,
          JOptionPane.NO_OPTION,
          null,
          new Object[] { "Ok"}, 
          "");
  }
  
  if(dst[0]!='0' && dst[0]!='1' && dst[0]!='2'){
     JOptionPane.showOptionDialog(
          this,
          "El formato de hora debe ser [0-2][0-3]:[0-5][0-9]:[0-5][0-9]", //Mensaje
          "",
          JOptionPane.OK_OPTION,
          JOptionPane.NO_OPTION,
          null,
          new Object[] { "Ok"}, 
          "");
  }
  if(dst[1]!='0' && dst[1]!='1' && dst[1]!='2' && dst[1]!='3'){
     JOptionPane.showOptionDialog(
          this,
          "El formato de hora debe ser [0-2][0-3]:[0-5][0-9]:[0-5][0-9]", //Mensaje
          "",
          JOptionPane.OK_OPTION,
          JOptionPane.NO_OPTION,
          null,
          new Object[] { "Ok"}, 
          "");
  }
  if(dst[2]!='0' && dst[2]!='1' && dst[2]!='2' && dst[2]!='3' && dst[2]!='4' && dst[2]!='5'){
     JOptionPane.showOptionDialog(
          this,
          "El formato de hora debe ser [0-2][0-3]:[0-5][0-9]:[0-5][0-9]", //Mensaje
          "",
          JOptionPane.OK_OPTION,
          JOptionPane.NO_OPTION,
          null,
          new Object[] { "Ok"}, 
          "");
  }
  if(dst[3]!='0' && dst[3]!='1' && dst[3]!='2' && dst[3]!='3' && dst[3]!='4' && dst[3]!='5' && dst[3]!='6' && dst[3]!='7' && dst[3]!='8' && dst[3]!='9'){
     JOptionPane.showOptionDialog(
          this,
          "El formato de hora debe ser [0-2][0-3]:[0-5][0-9]:[0-5][0-9]", //Mensaje
          "",
          JOptionPane.OK_OPTION,
          JOptionPane.NO_OPTION,
          null,
          new Object[] { "Ok"}, 
          "");
  }
  if(dst[4]!='0' && dst[4]!='1' && dst[4]!='2' && dst[4]!='3' && dst[4]!='4' && dst[4]!='5'){
     JOptionPane.showOptionDialog(
          this,
          "El formato de hora debe ser [0-2][0-3]:[0-5][0-9]:[0-5][0-9]", //Mensaje
          "",
          JOptionPane.OK_OPTION,
          JOptionPane.NO_OPTION,
          null,
          new Object[] { "Ok"}, 
          "");
  }
  if(dst[5]!='0' && dst[5]!='1' && dst[5]!='2' && dst[5]!='3' && dst[5]!='4' && dst[5]!='5' && dst[5]!='6' && dst[5]!='7' && dst[5]!='8' && dst[5]!='9'){
     JOptionPane.showOptionDialog(
          this,
          "El formato de hora debe ser [0-2][0-3]:[0-5][0-9]:[0-5][0-9]", //Mensaje
          "",
          JOptionPane.OK_OPTION,
          JOptionPane.NO_OPTION,
          null,
          new Object[] { "Ok"}, 
          "");
  }
  
  agreg.setQuery("INSERT INTO CALENDARIO VALUES ('" + actividad + "','" + fecha + "','" + hora + "','" + this.equipo + "')");
  agreg.actualizar();
  agreg.cerrar(); 
  this.setVisible(false);
  }
  catch (Exception e){}
}//GEN-LAST:event_jToogleButtonOk

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(EventoAgregar.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(EventoAgregar.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(EventoAgregar.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(EventoAgregar.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the dialog */
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                EventoAgregar dialog = new EventoAgregar(fecha, equipo);
                dialog.addWindowListener(new java.awt.event.WindowAdapter() {

                    @Override
                    public void windowClosing(java.awt.event.WindowEvent e) {
                        System.exit(0);
                    }
                });
                dialog.setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton2;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JTextArea jTextArea1;
    private javax.swing.JTextField jTextField1;
    private javax.swing.JToggleButton jToggleButton1;
    // End of variables declaration//GEN-END:variables
}
